package com.cqrt.service.impl;

import com.cqrt.mapper.RTEnumerationDefMapper;
import com.hustcad.plm.rpm.entityconvert.BaseConvert;
import com.hustcad.plm.rpm.model.entity.meta.TyppmEnumerationDef;
import com.hustcad.plm.rpm.service.impl.meta.TyppmEnumerationDefServiceImpl;
import com.hustcad.plm.rpm.service.meta.TyppmEnumerationDefService;
import com.ty.basic.constant.CommonConstant;
import com.ty.basic.entity.enumeration.EnumerationDefDO;
import com.ty.basic.session.TyAccountContext;
import com.ty.ppm.api.service.meta.EnumerationDefService;
import com.ty.ppm.model.dto.meta.EnumerationDefDTO;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Primary
@Service
public class RTTyppmEnumerationDefServiceImpl extends TyppmEnumerationDefServiceImpl {
    @Resource
    private BaseConvert baseConvert;
    @Resource
    private RTEnumerationDefMapper rtEnumerationDefService;
    @Resource
    private EnumerationDefService enumerationDefService;

    @Override
    public List<TyppmEnumerationDef> getAllEnumerationDef() {
        EnumerationDefDO remoteParams = new EnumerationDefDO();
        remoteParams.setMarkfordelete(0L);
        List<EnumerationDefDTO> enumerationDefDTOS = rtEnumerationDefService.listAllEnumerationDef( CommonConstant.GET_LOCALE_PROPERTY_VALUE_LANGUAGE.get(
                TyAccountContext.getLanguage()));
        return baseConvert.copyToList(enumerationDefDTOS, TyppmEnumerationDef.class);
    }

    @Override
    public void insert(TyppmEnumerationDef enumerationDef) {
        EnumerationDefDTO params = this.baseConvert.copyProperties(enumerationDef, EnumerationDefDTO.class);
        params.setSystem(2);
        this.enumerationDefService.insert(params);
        this.enumerationDefService.updateEnumerationDef(params);
    }
}
